package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buba.service.AdjustmentRecordService;
import common.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import entity.salary.AdjustmentRecord;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-21
 */
@RestController
@RequestMapping("/adjustment-record")
public class AdjustmentRecordController {

    @Resource
    private AdjustmentRecordService adjustmentRecordService;

    /* *
     * @Author: beisheng
     * @Descriprion: 根据人员ID查询调整记录
     * @Date: 2023/3/21 19:34
     * @Return: common.R
     * @Param: [accId]
     */

    @GetMapping("/selAdjustByAccId/{accId}")
    public R selAdjustByAccId(@PathVariable("accId") Integer accId){
        List<AdjustmentRecord> adjustmentRecords = adjustmentRecordService.selAdjustByAccId(accId);
        return R.success(adjustmentRecords);
    }
    /**
     * 功能描述: 新增或更新
     *
     * @param adjustmentRecord
     * @return
     * @throws
     * @Author: beisheng
     */
    @PostMapping("/save")
    public R save(@RequestBody AdjustmentRecord adjustmentRecord) {
        adjustmentRecordService.saveOrUpdate(adjustmentRecord);
        return R.success();
    }

    /**
     * 功能描述: 删除
     *
     * @param id
     * @return
     * @throws
     * @Author: beisheng
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        adjustmentRecordService.removeById(id);
        return R.success();
    }

    /**
     * 功能描述: 批量删除
     *
     * @param ids
     * @return
     * @throws
     * @Author: beisheng
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        adjustmentRecordService.removeByIds(ids);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: beisheng
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(adjustmentRecordService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: beisheng
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(adjustmentRecordService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: beisheng
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<AdjustmentRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(adjustmentRecordService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}
